package com.zshy.base.core.contract.exception;

import com.zshy.base.core.contract.enums.IEnum;
import com.zshy.base.core.contract.enums.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Bean转换异常
 *
 * @author zhouhengzhe
 * @公众号 小白的Java进阶之路
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BeanConversionException extends ServiceException {

    private final Integer code;

    private final String message;

    public BeanConversionException() {
        this(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getDesc());
    }

    public BeanConversionException(String message) {
        this(ResultCodeEnum.FAIL.getCode(), message);
    }

    public BeanConversionException(Integer code, String message) {
        this.message = message;
        this.code = code;
    }

    public BeanConversionException(Throwable e) {
        this(e.getMessage());
    }

    public BeanConversionException(IEnum<Integer> resultCode) {
        this(resultCode.getCode(), resultCode.getDesc());
    }

}
